#!/usr/bin/env python
"""
simpleclass.py
Library for manipulating class attribute

Copyright (C) 2007 Aurele Duda, contact@aurele-origami.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""
import re

def parse(s) :
    """
    Create a list from the value of a class attribute
    """
    delim = re.compile(r'[ \t\r\n,]+')
    return delim.split(s)
def format(l) :
    """
    Format an given class attribute from a list
    """
    return "".join(["".join(i)+" " for i in l])
def add(l, name, pos=-1) :
    """
    add a class to the class attribute at the given position
    """
    if isinstance(name, "list") :
        [l.insert(i,pos) for i in name]
    else : l.insert(name,pos)
def remove(l, name) :
    """
    remove the class name from a class list.
    """
    l.pop(name)